//
//  YPMessageTableViewCell.m
//  ChengHuiTong
//
//  Created by KiVen on 15/11/24.
//  Copyright © 2015年 张文权. All rights reserved.
//

#import "YPMessageTableViewCell.h"
#import "NSDate+Extension.h"

@implementation YPMessageTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self != nil) {
        
        
        _badgeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 10, 10)];
        _badgeLabel.backgroundColor = [UIColor redColor];
        _badgeLabel.layer.cornerRadius = 5;
        _badgeLabel.clipsToBounds = YES;
        
//        _badgeLabel.hidden = YES;
        [self.contentView addSubview:_badgeLabel];
        
        UIView * cellView = [[UIView alloc]initWithFrame:CGRectMake(5, 5, SCREEN_WIDTH-10, 95)];
//        cellView.backgroundColor = [UIColor grayColor];
        cellView.layer.cornerRadius =5;
        cellView.clipsToBounds = YES;
        cellView.layer.borderWidth =1;
        cellView.layer.borderColor = kColor_cellBorderColor.CGColor;
        [self.contentView addSubview:cellView];

       
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, 100, 20)];
//        _titleLabel.backgroundColor = [UIColor orangeColor];
        _titleLabel.text = @"待收金额";
        [cellView addSubview:_titleLabel];
        
        
        _timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-5-5-100-5, 5, 100, 20)];
//        _timeLabel.backgroundColor = [UIColor yellowColor];
        _timeLabel.font = [UIFont systemFontOfSize:12];
        _timeLabel.text = @"昨天 22:00";
        _timeLabel.textAlignment = NSTextAlignmentRight;
        [cellView addSubview:_timeLabel];
        
        
        _contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, CGRectGetMaxY(_titleLabel.frame), SCREEN_WIDTH-30, 40)];
        _contentLabel.numberOfLines = 2;
        _contentLabel.font = [UIFont systemFontOfSize:12];
//        _contentLabel.backgroundColor = [UIColor greenColor];
        _contentLabel.text = @"标编号:CHT007599,红酒资金周转（到期还本）满标复审，增加待收";
        [cellView addSubview:_contentLabel];
        
        
    }
    return self;
}

- (void)setContent:(YPStationMessageModel *)stationMessageModel{
    

    _titleLabel.text = stationMessageModel.title;
    

//    NSString *str = stationMessageModel.addtime;//时间戳
////    NSTimeInterval time=[str doubleValue]+28800;//因为时差问题要加8小时 == 28800 sec
//    NSTimeInterval time=[str doubleValue];//因为时差问题要加8小时 == 28800 sec
//
//    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
//
//    //实例化一个NSDateFormatter对象
//    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//    //设定时间格式,这里可以设置成自己需要的格式
//    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
//    
//    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
//    
//    NSLog(@"currentDateStr%@",currentDateStr);
//    
//    _timeLabel.text = currentDateStr;
//    
    
    _timeLabel.text = [NSDate created:stationMessageModel.addtime];
    
    _contentLabel.text =stationMessageModel.content;
    
    if ([stationMessageModel.status intValue]==0) {
        
        _badgeLabel.hidden = NO;
        
    }else{
        
        _badgeLabel.hidden = YES;
  
    }

}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
